package com.wqtz.chechai.utils;

import android.app.ActivityManager;
import android.content.Context;

import com.orhanobut.logger.Logger;

import java.util.List;

/**
 * 项目名称： CheChai
 * 创建人 : Liberation
 * 创建时间: 2016/12/19 17:16
 */

public class ActivityUtils {
	public static boolean isBackground(Context context) {

		ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
		List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
		for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
			if (appProcess.processName.equals(context.getPackageName())) {
				if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND) {
				//	Logger.e("后台", appProcess.processName);
					return true;
				}else{
				//	Logger.e("前台", appProcess.processName);
					return false;
				}
			}
		}
		return false;
	}
}
